//到货通知单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var flag=thisform.find('input[name=flag]:checked').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		$('#printorderGreenDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#printorderGreenDatagrid').datagrid({ 
			queryParams:{
				order_no:order_no,
				mailNo:mailNo,
				receiveMan:receiveMan,
				start_time:start_time,
				end_time:end_time,
				flag:flag
			}
		});
	})
	
	$('.AdvanceSearch').click(function(){
		$('#printAdvanceSearch').toggle(100);
	})

	$('#printorderGreenDatagrid').datagrid({
		//url:getprintorderGreenUrl+"?randnum="+Math.floor(Math.random()*1000000),
		url:getprintorderGreenUrl,
		title:'订单管理',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'order_no',title:'订单编号',sortable:true},
		{field:'logistics_no',title:'电子面单号',sortable:true},
		{field:'user_name',title:'收件人姓名',sortable:true},
		{field:'user_idcard',title:'身份证号',sortable:true},
		{field:'user_phone',title:'收件人电话',sortable:true},
		{field:'user_address_full',title:'收件人地址',sortable:true},
		{field:'flag',title:'状态',sortable:true,
			formatter:function(val,rowData,rowIndex){
				if(val=='正常'){
					return '<img src="./Public/Common/easyui/images/icons/flag_green.png" />';
				}
				if(val=='其它'){
					return '<img src="./Public/Common/easyui/images/icons/flag_yellow.png" />';
				}
				if(val=='暂存'){
					return '<img src="./Public/Common/easyui/images/icons/flag_red.png" />';
				}
			}
		},
		{field:'add_time',title:'推送时间',sortable:true}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
printorderGreenObj={
	showAll:function(){//显示默认条件下所有数据
		$('#printorderGreenDatagrid').datagrid({ queryParams:''});
	},
	excelinBar:function(){//导入Excel
		var index=layer.open({
            type: 2,
            title: '导入数据',
            shadeClose: true,
            shade: 0.5,
            area: ['1000px', '150px'],
            content: importurl+'/import/importPushorder'
        });
	},
	excelBar:function(){//导出excel
		var thisform=$('#printorderGreenSearchForm');
		// console.log(thisform);
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		console.log(order_no);
		url=getprintorderGreenUrl+"&excel=1&rows=6000";
		if(order_no!=''){
			url=url+"&order_no="+order_no;
		}
		if(mailNo!=''){
			url=url+"&mailNo="+mailNo;
		}
		if(receiveMan!=''){
			url=url+"&receiveMan="+receiveMan;
		}
		if(start_time!=0){
			url=url+"&start_time="+start_time;
		}
		if(end_time!=0){
			url=url+"&end_time="+end_time;
		}
		window.location.href=url;
	},
	reloadBar:function(){//刷新数据
		$('#printorderGreenDatagrid').datagrid('reload');
	},
	save:function(url){//编辑后保存数据
		$('#booksInfoEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	 var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#booksInfoEditDialog').dialog('close');
                    });
                }else{
                    $('#booksInfoEditDialog').dialog('close');      
                    $('#printorderGreenDatagrid').datagrid('reload');    
                }
            }
        });
	},
	editBar:function(){//显示编辑框
		var booksInfoRow=$('#printorderGreenDatagrid').datagrid('getSelections');
        if (booksInfoRow.length>1){		            	
            $.messager.alert('提示','一次只能修改一条记录!','info');
        }else if(booksInfoRow.length==1){            	
        	$('#booksInfoEditDialog').dialog('open').dialog('setTitle','编辑');
            $('#booksInfoEditForm').form('load',booksInfoRow[0]);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	flagBar:function(value){
		var authUserRow=$('#printorderGreenDatagrid').datagrid('getSelections');
		var text='确定修改吗！';
        if (authUserRow.length>0){
        	$.messager.confirm('提示',text,function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<authUserRow.length;i++){
                		ids.push(authUserRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(flagUrl,{id:id,value:value},function(result){
                        if (result.status){
                            $('#printorderGreenDatagrid').datagrid('reload');
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	}
}